package com.junjie.checkin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.junjie.checkin.entity.TPointRecord;
import com.junjie.checkin.entity.TStudentGift;
import com.junjie.checkin.request.pointRecord.PointRecordAdminPageRequest;
import com.junjie.checkin.request.pointRecord.PointRecordPageRequest;
import com.junjie.checkin.response.admin.DisciplinaryRecordsResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author 洪浚杰
 * @description
 * @date 2025/6/17 15:06
 */
@Mapper
public interface PointRecordMapper extends BaseMapper<TPointRecord> {
    Page<TPointRecord> pageQueryPointRecordList(@Param("userId")Integer userId,
                                                @Param("type")String relatedType,
                                                @Param("remark")String remark,
                                                @Param("increase")Boolean increase);

    /**
     * 获取用户累计获得积分
     * @param id
     * @return
     */
    @Select("select COALESCE(SUM(change_point), 0) from t_point_record where change_point > 0 and user_id = #{id}")
    Integer getUserEarnPoints(Integer id);

    /**
     * 获取用户累计扣除积分
     * @param id
     * @return
     */
    @Select("select COALESCE(SUM(change_point), 0) from t_point_record where change_point < 0 and user_id = #{id}")
    Integer getUserLosePoints(Integer id);

    /**
     * 获取用户积分记录
     * @param request
     * @return
     */
    Page<DisciplinaryRecordsResponse> getPointRecordPage(PointRecordAdminPageRequest request);
}
